package com.example.springbootsfzy.service.sunnan;

import com.example.springbootsfzy.domain.PsychologicalKnowledge;
import com.example.springbootsfzy.domain.PublicWelfareActivities;
import com.example.springbootsfzy.mapper.PublicWelfareActivitiesMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PublicWelfareActivitiesService {
    @Autowired
    private PublicWelfareActivitiesMapper publicWelfareActivitiesMapper;


    /**
     * 分页查询公益活动
     * @param pageNum 当前页码
     * @param pageSize 每页显示的数量
     * @return PageInfo
     */
    public PageInfo<PublicWelfareActivities> getPublicWelfareActivities(int pageNum, int pageSize) {
        // 使用 PageHelper.startPage 设置分页
        PageHelper.startPage(pageNum, pageSize);
        Page<PublicWelfareActivities> psychologicalKnowledges = publicWelfareActivitiesMapper.getAllArticles();
        return new PageInfo<>(psychologicalKnowledges);
    }

    /**
     * 添加公益活动
     * @param publicWelfareActivities 公益活动对象
     * return int 响应结果
     */
    public int addPublicWelfareActivities(PublicWelfareActivities publicWelfareActivities) {
        return publicWelfareActivitiesMapper.insert(publicWelfareActivities);
    }

    /**
     * 删除公益活动
     * @param id 公益活动id
     * return int 响应结果
     */
    public int deletePublicWelfareActivities(int id) {
        return publicWelfareActivitiesMapper.deleteByPrimaryKey(id);
    }

    /**
     * 修改公益活动
     */
    public int updatePublicWelfareActivities(PublicWelfareActivities publicWelfareActivities) {
        return publicWelfareActivitiesMapper.updateByPrimaryKey(publicWelfareActivities);
    }

    /**
     * 获取咨询师的公益活动
     */
    public PageInfo<PublicWelfareActivities> getArticlesByConsultantId(int pageNum, int pageSize, int consultantId) {
        PageHelper.startPage(pageNum, pageSize);
        Page<PublicWelfareActivities> publicWelfareActivities = publicWelfareActivitiesMapper.getArticlesByConsultantId(consultantId);
        return new PageInfo<>(publicWelfareActivities);
    }
}
